package com.lemon.smartsafety.view.item;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.entity.common.PanelRcvBaseDataI;
import com.lemon.smartsafety.utils.common.LoggerHelper;
import com.lemon.smartsafety.utils.common.StringUtils;

import cn.bingoogolapple.badgeview.BGABadgeTextView;

/**
 * Created by Cooliean on 16/3/25.
 */
public class PanelIconItemView extends LinearLayout {
    private LoggerHelper loggerHelper = new LoggerHelper(PanelIconItemView.class);
    private LinearLayout     mRippleView;
    private RelativeLayout mItemMainLayout;
    private View           mTopDivider, mBottomDivider;
    private ImageView mImageIcon, mImageArrow,mIv_status_light;
    private BGABadgeTextView mItemText;
    private TextView         mItemValue;


    private PanelRcvBaseDataI mData;

    private int mPosition;

    public PanelIconItemView(Context context) {
        super(context);
        initializeView(context);
    }

    public PanelIconItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initializeView(context);
    }

    public PanelIconItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initializeView(context);
    }

    private void initializeView(Context context) {
        inflate(context, R.layout.item_icon_title_tip_arrow, this);
    }


    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mRippleView = (LinearLayout) findViewById(R.id.ripple);
        mItemMainLayout = (RelativeLayout) findViewById(R.id.itemMainLayout);

        mTopDivider = findViewById(R.id.top_divider);
        mBottomDivider = findViewById(R.id.bottom_divider);
        mImageIcon = (ImageView) findViewById(R.id.imageIcon);
        mImageArrow = (ImageView) findViewById(R.id.imageArrow);
        mItemText = (BGABadgeTextView) findViewById(R.id.itemText);
        mItemValue = (TextView) findViewById(R.id.itemSubText);
        mIv_status_light= (ImageView) findViewById(R.id.iv_status_light);
    }

    public void showIsNewCircle() {
        if (mItemText != null) {
            mItemText.showCirclePointBadge();
        }
    }

    public void setData(PanelRcvBaseDataI data, int position) {
        mData = data;
        mPosition = position;
        mItemText.setText(data.getTitleI());
        mItemValue.setText(data.getValueI());
        mRippleView.setEnabled(!data.disable());
        if (data.getIconRes() != 0) {
            mImageIcon.setImageResource(data.getIconRes());
            mImageIcon.setVisibility(View.VISIBLE);
        } else {
            mImageIcon.setVisibility(View.GONE);
        }

        //设置默认值(相当于提示文本)
        if (StringUtils.isEmpty(data.getValueI())) {
            mItemValue.setVisibility(View.GONE);
            mItemValue.setText("");
        } else {
            mItemValue.setVisibility(View.VISIBLE);
            mItemValue.setText(StringUtils.nullValue(data.getValueI()));
        }

        if (data.showArrow()) {
            mImageArrow.setVisibility(View.VISIBLE);
        } else {
            mImageArrow.setVisibility(View.INVISIBLE);
        }

        if(data.isShowWarning()){
            mIv_status_light.setVisibility(View.VISIBLE);
            //该值为1 绿灯 ；-1红灯 ；2黄灯  其他值都为0
            switch (data.getStatus()){
                case 1:
                    mIv_status_light.setBackgroundResource(R.drawable.shape_circle_green);
                    break;
                case -1:
                    mIv_status_light.setBackgroundResource(R.drawable.shape_circle_red);
                    break;
                case 2:
                    mIv_status_light.setBackgroundResource(R.drawable.shape_circle_yellow);
                    break;
                default:
                    mIv_status_light.setBackgroundResource(R.drawable.shape_circle_white);
                    break;
            }

        }else{
            mIv_status_light.setVisibility(View.INVISIBLE);
        }


    }

    public LinearLayout getRippleView() {
        return mRippleView;
    }
  /*  public RippleView getRippleView() {
        return mRippleView;
    }*/
}
